package org.scboy.dbms.controller;

import java.util.List;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.dbms.service.InterLangService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/base/interlang")
@Menu("微服务管理系统.语言管理")
public class InterLangController {
	
	@Autowired
	InterLangService  service;
	
	/**
	 * 分页查询
	 * @param request
	 * @return
	 */
	@PostMapping("page")
	@Permission("分页查询")
	public Result page(@RequestBody Model params){
		Page page=service.page(params);
		return Result.Success(page);
	}
	
	/**
	 * 新增语言
	 * @param request
	 * @return
	 */
	@PostMapping("add")
	@Permission("新增语言")
	public Result add(@RequestBody Model params){
		if(service.add(params)){
			return Result.Success("INTER_LANG_ADD_SUCCESS");
		}else{
			return Result.Error("INTER_LANG_ADD_ERROR");
		}
	}
	
	/**
	 * 更新语言
	 * @param request
	 * @return
	 */
	@PutMapping("update")
	@Permission("更新语言")
	public Result update(@RequestBody Model params){
		if(service.update(params)){
			return Result.Success("INTER_LANG_UPDATE_SUCCESS");
		}else{
			return Result.Error("INTER_LANG_UPDATE_ERROR");
		}		
	}

	/**
	 * 获取语言信
	 * @param request
	 * @param lang
	 * @return
	 */
	@GetMapping("get")
	@Permission("获取语言信息")
	public Result get(String lang){
		return Result.Success(service.get(lang));
	}
	
	/**
	 * 删除语言
	 * @param request
	 * @param lang 主键
	 * @return
	 */
	@DeleteMapping("delete")
	@Permission("删除语言")
	public Result delete(String lang){
		if(service.delete(lang)){
			return Result.Success("INTER_LANG_DELETE_SUCCESS");
		}else{
			return Result.Error("INTER_LANG_DELETE_ERROR");
		}
	}
	
	/**
	 * 查询语言列表
	 * @param request
	 * @return
	 */
	@GetMapping("list")
	@Permission("查询语言列表")
	public Result list(){
		List<Model> list=service.list();
		return Result.Success(list);
	}
	
	/**
	 * 升序降序
	 * @param request
	 * @param id
	 * @return
	 */
	@PutMapping("sort")
	@Permission("升序降序")
	public Result sort(String id,int type){
		if(service.sort(id, type)){
			return Result.Success("INTER_LANG_SORT_SUCCESS");
		}else{
			return Result.Error("INTER_LANG_SORT_ERROR");
		}
	}
}
